home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7639 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: thor.tu.hac.com!collins
  2. From: collins@thor.tu.hac.com (Ron Collins)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Does Borland C++ 5.0 still work with normal C???
  5. Date: 27 Feb 1996 21:47:51 GMT
  6. Organization: Advanced Depot Systems
  7. Message-ID: <4gvu67$es7@hacgate2.hac.com>
  8. References: <n4mwd.33.000A228B@magg.net> <4gdkv3$q8a@druid.borland.com> <4ggsie$1fg@dopey.magg.net> <4gqdf7$jfo@redstone.interpath.net>
  9. NNTP-Posting-Host: thor.tu.hac.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Scott McMahan - Softbase Systems (softbase@mercury.interpath.net) wrote:
  13. : Dennis Hawkins (n4mwd@magg.net) wrote:
  14.  
  15. : : printf("%ld\n", (long) sizeof 'a');
  16.  
  17. : : and produce an EXE that generates '2' for the output.
  18.  
  19. : How do you get two out of this? A char is 1, and casting that to a long
  20. : is still 1, only it takes up more bytes. How can this evaluate to 2?
  21. : sizeof char being 1 is kinda hard-wired into the language.
  22.  
  23. The expression in question is "sizeof 'a'", which returns the size of
  24. an expression, not a type.  The result type of the expression 'a' is an
  25. int, not a char.  Therefore, "(sizeof 'a') => 2" is correct.
  26.  
  27.  
  28.             -- collins --
  29.